PROJ_03

DISTRIBUTED
API RATE LIMITER

Token Bucket based distributed rate limiting middleware built using Redis atomic operations to prevent API abuse and protect backend services from overload.

JAVA SPRING BOOT REDIS CONCURRENCY DISTRIBUTED SYSTEMS

OVERVIEW

This project was developed to protect backend services from excessive traffic and API abuse. The system uses a Token Bucket algorithm backed by Redis atomic operations to enforce rate limits consistently across multiple application instances. The solution sustained 10,000+ requests per second while maintaining sub-50ms validation latency under load.

ARCHITECTURE


+----------------------+
|      CLIENT          |
+----------+-----------+
           |
           v

+----------------------+
| SPRING BOOT API      |
+----------+-----------+
           |
           v

+----------------------+
| RATE LIMIT FILTER    |
+----------+-----------+
           |
           v

+----------------------+
| REDIS TOKEN BUCKET   |
+----------+-----------+
           |
     Tokens Available?
           |
      +----+----+
      |         |
     YES       NO
      |         |
      v         v

 Process     HTTP 429
 Request   Too Many Requests

TOKEN_BUCKET_ALGORITHM

Each client receives a bucket containing a fixed number of tokens. Every incoming request consumes one token. Tokens are replenished periodically at a configured rate. When the bucket becomes empty, additional requests are rejected until tokens become available again. This approach allows controlled bursts while preventing backend overload.

REQUEST_FLOW

  1. 1. Request arrives at API Gateway.
  2. 2. Rate Limiter intercepts request.
  3. 3. Redis bucket state is retrieved.
  4. 4. Token availability is checked.
  5. 5. Token is consumed atomically.
  6. 6. Request proceeds or is rejected.

REDIS_ATOMIC_OPERATIONS

Atomic Updates

Redis guarantees bucket state consistency during concurrent access.

High Throughput

In-memory operations enable extremely fast request validation.

CONCURRENCY_HANDLING

Multiple application instances may validate requests simultaneously. Redis atomic operations ensure token counts remain consistent under heavy concurrent traffic. This prevents race conditions and ensures accurate rate limit enforcement across distributed deployments.

PERFORMANCE

10K+

REQUESTS / SECOND

<50ms

VALIDATION LATENCY

0

RATE LIMIT BYPASS

LOAD_TESTING

Extensive concurrent load testing was performed to validate the correctness and scalability of the rate limiting mechanism.

10K+

Requests Per Second

0

Bypass Events

Stable

Under Sustained Load

ENGINEERING_CHALLENGES

Distributed State

Maintaining consistent bucket state across multiple application instances required Redis-backed atomic operations.

Race Conditions

Concurrent requests could attempt token consumption simultaneously. Atomic Redis commands ensured consistency.

High Throughput

The solution needed to validate requests with minimal latency while sustaining thousands of requests per second.

LESSONS_LEARNED

This project deepened my understanding of distributed systems, concurrency control, Redis internals and scalable API protection. It also provided hands-on experience with designing low-latency middleware capable of operating under high request volumes.

VIEW_SOURCE_CODE

Explore the Token Bucket implementation, Redis integration and load testing logic.

OPEN_GITHUB